home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / Shaders / TexturingAndModeling:AProceduralApproach / DPShaders / DPBrick.sl < prev    next >
Encoding:
Text File  |  1995-03-22  |  1.1 KB  |  46 lines

  1. #include "proctext.h"
  2.  
  3. #define BRICKWIDTH      0.25
  4. #define BRICKHEIGHT     0.08
  5. #define MORTARTHICKNESS 0.01
  6.  
  7. #define BMWIDTH         (BRICKWIDTH+MORTARTHICKNESS)
  8. #define BMHEIGHT        (BRICKHEIGHT+MORTARTHICKNESS)
  9. #define MWF             (MORTARTHICKNESS*0.5/BMWIDTH)
  10. #define MHF             (MORTARTHICKNESS*0.5/BMHEIGHT)
  11.  
  12. surface
  13. DPBrick(
  14.     uniform float Ka = 1;
  15.     uniform float Kd = 1;
  16.     uniform color Cbrick = color (0.5, 0.15, 0.14);
  17.     uniform color Cmortar = color (0.5, 0.5, 0.5);
  18.      )
  19. {
  20.     color Ct;
  21.     point Nf;
  22.     float ss, tt, sbrick, tbrick, w, h;
  23.     float scoord = s;
  24.     float tcoord = t;
  25.  
  26.     Nf = normalize(faceforward(N, I));
  27.  
  28.     ss = scoord / BMWIDTH;
  29.     tt = tcoord / BMHEIGHT;
  30.  
  31.     if (mod(tt*0.5,1) > 0.5)
  32.         ss += 0.5;  /* shift alternate rows */
  33.     sbrick = floor(ss); /* which brick? */
  34.     tbrick = floor(tt); /* which brick? */
  35.     ss -= sbrick;
  36.     tt -= tbrick;
  37.     w = step(MWF,ss) - step(1-MWF,ss);
  38.     h = step(MHF,tt) - step(1-MHF,tt);
  39.  
  40.     Ct = mix(Cmortar, Cbrick, w*h);
  41.  
  42.     /* diffuse reflection model */
  43.     Oi = Os;
  44.     Ci = Os * Ct * (Ka * ambient() + Kd * diffuse(Nf));
  45. }
  46.